from shared.graph_client import GraphClient

class ItemRestoreEngine:
    def __init__(self, graph_client: GraphClient):
        self.client = graph_client
        
    def restore_single_item(self, user_id: str, item_data: dict):
        """恢复单个邮件项"""
        return self.client.make_request(
            "POST",
            f"users/{user_id}/messages",
            data=item_data
        )
    
    def restore_attachment(self, message_id: str, attachment_data: dict):
        """恢复邮件附件"""
        return self.client.make_request(
            "POST",
            f"me/messages/{message_id}/attachments",
            data=attachment_data
        )
    
    def restore_folder_structure(self, user_id: str, folder_tree: list):
        """恢复文件夹结构"""
        batch_payload = {
            "requests": [
                {
                    "id": str(idx),
                    "method": "POST",
                    "url": f"/users/{user_id}/mailFolders",
                    "body": folder
                } for idx, folder in enumerate(folder_tree)
            ]
        }
        return self.client.make_request("POST", "$batch", data=batch_payload)